<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use DB;
use Markdown;
use App\Model\Art;

class ArticleController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
       $arts = Art::orderBy('id','desc')->paginate(6);
        // $art = new Art;
        //     $arts = $art->paginate(2);
        //$arts = Art::paginate(2);
       //dd($arts); die;
        return view('art.index',['arts'=>$arts]);
       
    }

    //
    public function create()
    {

        return view('art.add');
    }


    public function store(Request $request)
    {
        $art = Art::create($request->except('_token'));
        return redirect('/art');
    }

  
    public function show($id)
    {
        
        $art = Art::find($id);
        $art->content= Markdown::convertToHtml($art->content);
        return view('art.show',['art'=>$art]);
    }


    public function edit($id)
    {
        //$art = DB::table('arts')->where('id','=',$id)->first();
        $art = Art::find($id);
        return view('art.edit',['art'=>$art]);
    }

   
    public function update(Request $request, $id)
    {
      
        $art = Art::where('id','=',$id)
            ->update($request->except('_token','_method'));

        return redirect('/art');
    }

  
    public function destroy($id)
    {
       
        $art = Art::destroy($id);
        return redirect('/art');
    }


    public function getMk()
    {
        $str="<p>#    h1</p>";
        echo Markdown::convertToHtml($str);
    }



}

